package com.ssm.pre.service.impl;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.stereotype.Service;

import com.ssm.pre.service.WechatUrlService;
import com.ssm.util.Constants;
import com.ssm.util.object.InputObject;
import com.ssm.util.object.OutputObject;

@Service
public class WechatUrlServiceImpl implements WechatUrlService {

	/**
	 * 获取微信端网页请求路径
	 */
	@Override
	public void queryWechatUrlByList(InputObject inputObject, OutputObject outputObject) throws Exception {
		List<Map<String, Object>> beans = new ArrayList<Map<String, Object>>();
		beans.add(addFamilyUser());
		beans.add(addRepair());
		beans.add(addOption());
		beans.add(addProperty());
		beans.add(addElectric());
		beans.add(queryProperty());
		beans.add(queryElectric());
		int total = beans.size();
		outputObject.setBeans(beans);
		outputObject.settotal(total);
	}

	/**
	 * 住户登记——微信端用户注册
	 */
	public Map<String, Object> addFamilyUser() throws Exception{
		Map<String, Object> bean = new HashMap<String, Object>();
		String uuid = UUID.randomUUID().toString();
		//网页授权访问路径
		String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+Constants.APP_ID+"&redirect_uri="
				+ URLEncoder.encode(Constants.PATH+"html/wechat_signup/wechat_signup.html","UTF-8")
				+"&response_type=code&scope=snsapi_userinfo&state="+uuid+"#wechat_redirect";
		bean.put("web", "住户登记");
		bean.put("url", url);
		return bean;
	}
	
	/**
	 * 快捷报修——微信端报修
	 */
	public Map<String, Object> addRepair() throws Exception{
		Map<String, Object> bean = new HashMap<String, Object>();
		String uuid = UUID.randomUUID().toString();
		//网页授权访问路径
		String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+Constants.APP_ID+"&redirect_uri="
				+ URLEncoder.encode(Constants.PATH+"html/wechat_repair/wechat_repair.html","UTF-8")
				+"&response_type=code&scope=snsapi_userinfo&state="+uuid+"#wechat_redirect";
		
		bean.put("web", "快捷报修");
		bean.put("url", url);		
		return bean;
	}
	
	/**
	 * 意见反馈——微信端反馈
	 */
	public Map<String, Object> addOption() throws Exception{
		Map<String, Object> bean = new HashMap<String, Object>();
		String uuid = UUID.randomUUID().toString();
		//网页授权访问路径
		String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+Constants.APP_ID+"&redirect_uri="
				+ URLEncoder.encode(Constants.PATH+"html/wechat_option/wechat_option.html","UTF-8")
				+"&response_type=code&scope=snsapi_userinfo&state="+uuid+"#wechat_redirect";
		
		bean.put("web", "意见反馈");
		bean.put("url", url);		
		return bean;
	}
	
	/**
	 * 生活缴费——物业费
	 */
	public Map<String, Object> addProperty() throws Exception{
		Map<String, Object> bean = new HashMap<String, Object>();
		String uuid = UUID.randomUUID().toString();
		//网页授权访问路径
		String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+Constants.APP_ID+"&redirect_uri="
				+ URLEncoder.encode(Constants.PATH+"html/wechat_life/wechat_property.html","UTF-8")
				+"&response_type=code&scope=snsapi_userinfo&state="+uuid+"#wechat_redirect";
		
		bean.put("web", "物业缴费");
		bean.put("url", url);		
		return bean;
	}
	
	/**
	 * 生活缴费——电费
	 */
	public Map<String, Object> addElectric() throws Exception{
		Map<String, Object> bean = new HashMap<String, Object>();
		String uuid = UUID.randomUUID().toString();
		//网页授权访问路径
		String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+Constants.APP_ID+"&redirect_uri="
				+ URLEncoder.encode(Constants.PATH+"html/wechat_life/wechat_electric.html","UTF-8")
				+"&response_type=code&scope=snsapi_userinfo&state="+uuid+"#wechat_redirect";
		
		bean.put("web", "电费缴费");
		bean.put("url", url);	
		return bean;
	}
	
	/**
	 * 物业费查询(历史记录)
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> queryProperty() throws Exception{
		Map<String, Object> bean = new HashMap<String, Object>();
		String uuid = UUID.randomUUID().toString();
		//网页授权访问路径
		String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+Constants.APP_ID+"&redirect_uri="
				+ URLEncoder.encode(Constants.PATH+"html/wechat_life/wechat_propertyInfo.html","UTF-8")
				+"&response_type=code&scope=snsapi_userinfo&state="+uuid+"#wechat_redirect";
		
		bean.put("web", "物业费缴费记录");
		bean.put("url", url);	
		return bean;
	}
	
	/**
	 * 电费查询(历史记录)
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> queryElectric() throws Exception{
		Map<String, Object> bean = new HashMap<String, Object>();
		String uuid = UUID.randomUUID().toString();
		//网页授权访问路径
		String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+Constants.APP_ID+"&redirect_uri="
				+ URLEncoder.encode(Constants.PATH+"html/wechat_life/wechat_electricInfo.html","UTF-8")
				+"&response_type=code&scope=snsapi_userinfo&state="+uuid+"#wechat_redirect";
		
		bean.put("web", "电费缴费记录");
		bean.put("url", url);	
		return bean;
	}
}
